<?php
/**
 * Created by 项目.
 * User: xuguopeng
 * Date: 2020-06-22
 * Time: 17:32
 */

namespace app\api\controller\v1;


use app\api\model\Image;
use app\api\model\LinFile;
use app\api\model\System;
use think\facade\Request;

class Invite
{
    // 创建用户分享图片
    public function setInviteImg()
    {
        $data = Request::post();
        $system = System::get(1);
        $file = fopen('./qr/'.$data['name'].'.png',"w");//打开文件准备写入
        fwrite($file,$data['res']);//写入,$res为图片二进制内容
        fclose($file);//关闭
        $image = Image::where('id',$system['invite_img_id'])->find();
        $flie = LinFile::where('id',$image['file_id'])->find();
        $filename = './uploads/'.$flie['path'];
        $image = \think\Image::open($filename); //要加水印的图片 两个字 array(445,360)
        $image->water('./qr/'.$data['name'].'.png',array(230,570),100)->save('./qr/'.$data['name'].'.png');//添加图片
        return config('setting.invite_img_prefix').$data['name'].'.png';
    }

}